package com.itheima.model.vo;

import com.itheima.model.domain.Options;
import com.itheima.model.domain.Questions;
import com.itheima.model.domain.TestSoul;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class TestSoulVo implements Serializable {
    private String id;//问卷编号
    private String name;//问卷名称
    private String cover;//封面
    private String level;//级别
    private Integer star;//性别
    private List<QuestionsVo> questions;//试题
    private Integer isLock;//是否锁住
    private String reportId;//最新报告

    public static TestSoulVo init(TestSoul testSoul, List<Questions> rQuestions, Map<Long, List<Options>> rOptionsMap) {
        TestSoulVo vo = new TestSoulVo();
        BeanUtils.copyProperties(testSoul, vo);
        vo.setId(testSoul.getNumber());
        //questions成员变量
        List<QuestionsVo> questions1 = new ArrayList<>();
        for (Questions rQuestion : rQuestions) {
            List<Options> rOptions = rOptionsMap.get(rQuestion.getId());//根据quesionId获取options集合
            questions1.add(QuestionsVo.init(rQuestion, rOptions));//questions参数和其中的options参数
        }
        vo.setQuestions(questions1);
        return vo;

    }
}




